import { isString } from './is'

export function predicateOrder (key, ascending = true) {
  const order = ascending ? 1 : -1
  return (a, b) => {
    return (a[key] - b[key]) * order
  }
}

export function predicateGroup (key) {
  return (item) => {
    return item[key]
  } 
}

export function predicateSelect (selectors) {
  return (item => {
    const result = {}
    const keys = isString(selectors) ? [selectors]: selectors
    keys.forEach(key => {
      result[key] = item[key]
    })
    return result
  })
}
